package com.goldmantis.alitrip.controller;

import com.alibaba.fastjson.JSON;
import com.goldmantis.alitrip.service.ApprovalNewService;
import com.goldmantis.alitrip.service.ApprovalUpdateService;
import com.taobao.api.internal.util.StringUtils;
import com.taobao.api.request.AlitripBtripApprovalNewRequest;
import com.taobao.api.request.AlitripBtripApprovalNewRequest.OpenItineraryInfo;
import com.taobao.api.request.AlitripBtripApprovalUpdateRequest;
import com.taobao.api.response.AlitripBtripApprovalNewResponse;
import com.taobao.api.response.AlitripBtripApprovalUpdateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author:Shmily
 * @Description:
 * @Date:Create in 17:55 2018/1/15
 */
@Controller
@CrossOrigin(value = "*",maxAge = 3600)
@RequestMapping("approval/")
public class ApprovalUpdateController {

    private static final Logger logger = LoggerFactory.getLogger(ApprovalUpdateController.class);

    @Autowired
    private ApprovalUpdateService approvalUpdateService;

    /**
     * 更新审批单状态
     * @param approveApplyRequest
     * @return
     */
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public ResponseEntity<AlitripBtripApprovalUpdateResponse> insertNewApproval(AlitripBtripApprovalUpdateRequest.OpenApproveApplyRq approveApplyRequest) {
        try {
            if(logger.isInfoEnabled()){
                logger.info("收到数据:"+ JSON.toJSONString(approveApplyRequest));
            }
            AlitripBtripApprovalUpdateResponse rsp = approvalUpdateService.updateApproval(approveApplyRequest);
            if(logger.isInfoEnabled()){
                logger.info("单据更新成功:"+JSON.toJSONString(rsp));
            }
            return ResponseEntity.ok(rsp);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("状态更新出错，item="+approveApplyRequest+"/r/n错误信息："+e.getStackTrace());
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
